package com.zjdiepu.www.response;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;

import com.zjdiepu.www.security.base.bean.BaseBean;
import com.zjdiepu.www.security.base.enums.ResultCode;

/**
 * 类描述: 通用响应对象 <br/>     
 * 项目名称:zjdiepu-client <br/> 
 * 类名称:BaseResponse <br/>     
 * 创建人:xiongxiaotun <br/> 
 * 创建时间:2017年8月15日 下午2:25:02  <br/>   
 * 修改人:xiongxiaotun <br/> 
 * 修改时间: 2017年8月15日 下午2:25:02   <br/>  
 * 修改备注:   <br/> 
 * @version V1.0   <br/>
 */
@ApiModel(value="BaseResponse", description="通用响应对象")
public class BaseResponse<T extends BaseBean> implements Serializable {
	private static final long serialVersionUID = 1L;
	/**
	 * 结果码
	 */
	@ApiModelProperty(name="resultCode",required=true,value="结果码",example="0")
	private Integer resultCode;
	/**
	 * 提示信息
	 */
	@ApiModelProperty(name="resultMsg",required=true,value="提示信息",example="本次执行成功！【稻普控股集团】")
	private String resultMsg;
	/**
	 * 业务数据
	 */
	@ApiModelProperty(name="content",required=false, value="业务数据")
	private T content;
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title success  <br/>
	 * @Description 成功响应构建 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static <T extends BaseBean> BaseResponse<T> success() {
		return create(ResultCode.SUCCESS);
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title success  <br/>
	 * @Description 成功响应构建 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static <T extends BaseBean> BaseResponse<T> success(T o) {
		BaseResponse<T> result = success();
		result.setContent(o);
		return result;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title successWithBoolean  <br/>
	 * @Description 成功响应构建:布尔类型 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static BaseResponse<BooleanResponse> successWithBoolean(Boolean result) {
		 BaseResponse<BooleanResponse> response = success();
		 BooleanResponse content = new BooleanResponse(result);
		 response.setContent(content);
		 return response;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title failWithBoolean  <br/>
	 * @Description 成功响应构建:布尔类型 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static BaseResponse<BooleanResponse> failWithBoolean(ResultCode resultCode) {
		 BaseResponse<BooleanResponse> response = create(resultCode);
		 BooleanResponse content = new BooleanResponse(false);
		 response.setContent(content);
		 return response;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title failWithBoolean  <br/>
	 * @Description 成功响应构建:布尔类型 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static BaseResponse<BooleanResponse> failWithBoolean(Integer errorCode, String errorMsg) {
		 BaseResponse<BooleanResponse> response = create(errorCode, errorMsg);
		 BooleanResponse content = new BooleanResponse(false);
		 response.setContent(content);
		 return response;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title success  <br/>
	 * @Description 成功响应构建:字符串 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static BaseResponse<StringResponse> successWithString(String result) {
		 BaseResponse<StringResponse> response = success();
		 StringResponse content = new StringResponse(result);
		 response.setContent(content);
		 return response;
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title successWithNumber  <br/>
	 * @Description 成功响应构建:数字 <br/>
	 * @return
	 * @version V1.0  <br/>
	 */
	public static BaseResponse<NumberResponse> successWithNumber(Number result) {
		 BaseResponse<NumberResponse> response = success();
		 NumberResponse content = new NumberResponse(result);
		 response.setContent(content);
		 return response;
	}
	
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title create  <br/>
	 * @Description 标准响应构建  <br/>
	 * @param resultCode
	 * @return
	 * @version V1.0  <br/>
	 */
	public static <T extends BaseBean> BaseResponse<T> create(ResultCode resultCode) {
		if(resultCode == null) {
			resultCode = ResultCode.SUCCESS;
		}
		return create(resultCode.getCode(), resultCode.getName());
	}
	
	/**
	 * @author xiongxiaotun <br/>
	 * @Title create  <br/>
	 * @Description 自定义响应构建  <br/>
	 * @param resultCode
	 * @param resultMsg
	 * @return
	 * @version V1.0  <br/>
	 */
	public static <T extends BaseBean> BaseResponse<T> create(Integer resultCode, String resultMsg) {
		return new BaseResponse<T>(resultCode, resultMsg);
	}
	
	public BaseResponse() {
		super();
	}

	public BaseResponse(Integer resultCode, String resultMsg) {
		super();
		this.resultCode = resultCode;
		this.resultMsg = resultMsg;
	}
	
	public BaseResponse(Integer resultCode, String resultMsg, T content) {
		super();
		this.resultCode = resultCode;
		this.resultMsg = resultMsg;
		this.content = content;
	}
	
	public Integer getResultCode() {
		return resultCode;
	}
	public void setResultCode(Integer resultCode) {
		this.resultCode = resultCode;
	}
	public String getResultMsg() {
		return resultMsg;
	}
	public void setResultMsg(String resultMsg) {
		this.resultMsg = resultMsg;
	}

	public T getContent() {
		return content;
	}

	public void setContent(T content) {
		this.content = content;
	}
}
